#!/bin/bash
# vim:  fdm=marker fmr=[[[,]]] cms=\ #%s#

GENERATE()
{ #[[[#
    $CLIENT $ADDR GENERATE
} #]]]#

SUBMIT()
{ #[[[#
    local token
    read -p "token: " token
    local code
    read -p "code: " code
    $CLIENT $ADDR SUBMIT "${token}" "${code}"
} #]]]#

TRYSUBMIT()
{ #[[[#
    local token
    read -p "token: " token
    local code
    read -p "code: " code
    $CLIENT $ADDR TRYSUBMIT "${token}" "${code}"
} #]]]#

main()
{ #[[[#
    if [[ ! -x $CLIENT ]]
    then
        echo "client not found"
        return 1
    fi

    local option
    read -p "\
Services:
    1) GENERATE
    2) SUBMIT
    3) TRYSUBMIT
Input: " option
    if [[ -z $option ]]
    then
        echo  "Error: option invalid"
        return 1
    fi
    case $option in
        1) GENERATE ;;
        2) SUBMIT ;;
        3) TRYSUBMIT ;;
        *)
            echo "Error: option($option) not supported"
            return 1
            ;;
    esac
} #]]]#

bin_path=$(dirname $0)
if [ ${bin_path:0:1} != '/' ]
then
    bin_path=$(pwd)/$bin_path
fi
CLIENT=$bin_path/../../tool/snclient
ADDR=localhost:10050

main
exit $?
